//
//  MKCustomViewController.m
//  UILbrary
//
//  Created by mac on 17/3/7.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "MKCustomViewController.h"

@interface MKCustomViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableview;

@end

@implementation MKCustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage *backImage = [UIImage imageNamed:@"archives_callout_bg"];
    
    self.view.layer.contents =(id)backImage.CGImage;
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tableview];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    CGRect frame = self.view.bounds;
    frame.size.height = frame.size.height - 10;
    self.tableview.frame = frame;
    [self.tableview reloadData];
    
    [self.backgroundButton removeFromSuperview];
    [self.view addSubview:self.backgroundButton];
}


- (void)buttonClick{
    NSLog(@"%s --- %s",__FILE__,__func__);
}

- (void)backgroundButtonClick{

    NSLog(@"%s --- %s",__FILE__,__func__);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"%s",__func__);
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = (self.tableview.frame.size.height - 40)/self.titleArr.count;
    if (indexPath.row == 5) {
        return height * 2;
    }
    return height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = self.titleArr[indexPath.row];
    [cell.textLabel setTextColor:[UIColor whiteColor]];
    cell.textLabel.font = [UIFont systemFontOfSize:13.0];
    cell.textLabel.numberOfLines = 0;
    return cell;
}

#pragma mark - lazy methods

- (UITableView *)tableview{
    if (!_tableview) {
        CGRect frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 10);
        _tableview = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain] ;
        _tableview.backgroundColor = [UIColor clearColor];
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.delegate = self;
        _tableview.dataSource = self
        ;
    }
    return _tableview;
}

- (UIButton *)backgroundButton{
    if (!_backgroundButton) {
        _backgroundButton = [[UIButton alloc] initWithFrame:self.view.bounds];
        [_backgroundButton addTarget:self action:@selector(backgroundButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backgroundButton;
}

@end
